/**
 * This file was created by Julia Deeb and Nick Popescu for use in SpaceTrader
 */
import java.awt.Container;
import java.io.Serializable;
import java.util.Random;

/**
 * This class is used as a storage space for some of the game's objects.
 * 
 * @author Nick Popescu, Julia Deeb
 * @version 1.0
 */
public class Game implements Serializable {
    /**
     * This represnts the user's player
     */
    public static Player Player = null;

    /**
     * This represents the space that the user travels on
     */
    public static Space Space = null;

    /**
     * This represents the game screen used in the UI
     */
    public static GameScreen GameScreen = null;

    /**
     * This represents the initial configuration screen used in the UI
     */
    public static InitConfigScreen InitConfigScreen = null;

    /**
     * This string represents the event that has occured on the planet
     */
    public static String Event = "none";

    /**
     * This string represents a Random crisis message to be displayed to the
     * user
     */
    public static String Crisis = "none";

    /**
     * This represents the ability to create Random values
     */
    private static final Random RAND = new Random();

    /**
     * This represents the start screen to be used in the UI
     */
    public static StartScreen StartScreen = null;

    /**
     * THis represents the new player screen to be used in the UI
     */
    public static Container NewPlayerScreen = null;
    
    /**
     * Random seed for random generator
     */
    public static final int RANDSEED = 10;

    /**
     * This represents the saved data file to be loaded in the future
     */
    public static String SaveFilename = "savefile.dat";

    /**
     * This array represents all possible Random events that can occur on a
     * planet
     */
    private static final String[] OUTCOMES = { "drought", "cold", "cropfail", "war",
	    "boredom", "plague", "lack of workers" };
    
    /**
     * Random probability seed.
     */
    private static final int RANDPROB = 5;
    
    /**
     * This method creates a Random event that occurs on a planet based on a
     * probability at each turn
     */
    public static void randomEventGenerator() {
	final int chance = RAND.nextInt(RANDSEED);
	final int probability = RANDPROB; 
	if (chance < probability) {
	    Event = OUTCOMES[RAND.nextInt(OUTCOMES.length)];
	} else {
	    Event = "none";
	}
    }

    /**
     * This array represents the NPCs that are involved when a radom event has
     * occured.
     */
    private static final String[] PERSON = { "Pirate", "Policeman",
	    "Intergalactical Security Agent", "Bandit", "Burly Farmer",
	    "Homeless Person" };
    
    /**
     * This array represents the amount of monies that can be added or
     * subtracted from the Person's wallet after an event has occured
     */
    
    private static final int[] AMOUNT = { 10, 20, 25, 15, 5, -5, -10, -20, -25, -100 }; // $codepro.audit.disable numericLiterals
									  
    /**
     * Crisis probability seed
     */
    
    private static final int CRISISPROB = 3;
    
    /**
     * This method creates a Random Crisis for the player at each turn based on
     * probabilities.
     */
    
    public static void randomCrisisGenerator() {
	final double money = Player.getWallet();
	final String per = PERSON[RAND.nextInt(PERSON.length)];
	final int change = AMOUNT[RAND.nextInt(AMOUNT.length)];

	final int probschance = RAND.nextInt(RANDSEED);
	final int probability = CRISISPROB;
	if (probschance <= probability) {
	    Crisis = "You ran into a " + per + ". You gained " + change
		    + " monies.";
	    Player.setWallet(money + change);
	} else {
	    Crisis = "none";
	}
    }

    /**
     * this method returns a string representing Game
     * 
     * @return a String representing Game
     */
    @Override
    public String toString() {
	return this.toString();
    }
    
    /**
     * This method sets the value of Player to the user inputed player
     * @param p the player inputed by the user 
     */
    public static void setPlayer(Player p){
	Player = p;
    }
    
    /**
     * This method sets the value of Space to the user inputed Space
     * @param s the space inputed by the user 
     */
    public static void setSpace(Space s){
	Space = s;
    }
    
    /**
     * This method sets the value of GameScreen to the user inputed GameScreen
     * @param g the GameScreen inputed by the user 
     */
    public static void setGameScreen(GameScreen g){
	GameScreen = g;
    }
}
